package moni.anyou.com.view.view.fragmentadapter;

import moni.anyou.com.view.R;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by YXY on 2017/6/17.
 */

public class DayAdapter extends RecyclerView.Adapter<DayAdapter.MyHolder> implements View.OnClickListener{

    private int[] icons;
    private String[] title;


    public DayAdapter(int[] icons,String[] title){
        this.icons=icons;
        this.title=title;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyHolder myHolder=new MyHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_day,parent,false));
        return myHolder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        holder.tvDay.setText(title[position]);
        holder.ivDay.setBackgroundResource(icons[position]);
        holder.ivDay.setTag(position);
        holder.ivDay.setOnClickListener(this);
    }

    @Override
    public int getItemCount() {
        return icons.length;
    }

    @Override
    public void onClick(View view) {
        int index = (int) view.getTag();

        Toast.makeText(view.getContext(),"正在开发中",Toast.LENGTH_SHORT).show();


    }

    class MyHolder extends RecyclerView.ViewHolder{
        private TextView tvDay;
        private ImageView ivDay;

        public MyHolder(View itemView) {
            super(itemView);
            tvDay = (TextView) itemView.findViewById(R.id.tv_adapter_day);
            ivDay= (ImageView) itemView.findViewById(R.id.iv_adapter_day);
        }
    }
}
